<?php
    define('DATABASE','dealscombined');
	require '/var/www/sandbox/dealscombined.co.uk/scripts/connect.php';
	$file = "/var/www/sandbox/dealscombined.co.uk/scripts/mapper/categories.json";
		
	// Select DB
	$db=mysql_select_db(DATABASE,$connect);
	if(!$db) {
		die('Can\'t use DATABASE : '.mysql_error());
	}
	
	$categories = array();
	$result = mysql_query("SELECT s.id, c.category AS department, s.category FROM subcategories s INNER JOIN categories c ON s.category_id = c.id");
	
	while($row = mysql_fetch_assoc($result)){
		
		$categories[$row['id']] = $row['department']. ' > ' .$row['category'];
	}
	
	file_put_contents($file, json_encode($categories));
?>